﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace CXMLStudioIDE.Common.EntityProperties
{
    /// <summary>
    /// Property Class for defining a property to be displayed in the PropertyForm
    /// </summary>
    public class EntityProperty
    {
        #region Declarations
        private string sName, sCategory, sDescription = string.Empty;
        private bool bReadOnly = false;
        private bool bVisible = true;
        private object objValue = null;
        private Type type;
        private DataBinding _DataBinding = null;
        #endregion

        #region Constructor
        public EntityProperty(string sName, object value, Type type, bool bReadOnly, bool bVisible, string sCategory, string sDescription, DataBinding dBinding)
        {
            this.sName = sName;
            this.objValue = value;
            this.type = type;
            this.bReadOnly = bReadOnly;
            this.bVisible = bVisible;
            this.sCategory = sCategory;
            this.sDescription = sDescription;
            this._DataBinding = dBinding;
        }
        #endregion

        #region Property Definitions

        public DataBinding DataBinding
        {
            get { return _DataBinding; }
            set { _DataBinding = value; }
        }

        public Type Type
        {
            get { return this.type; }
        }

        public bool ReadOnly
        {
            get
            {
                return this.bReadOnly;
            }
        }

        public string Name
        {
            get
            {
                return this.sName;
            }
        }

        public bool Visible
        {
            get
            {
                return this.bVisible;
            }
        }

        public object Value
        {
            get
            {
                return this.objValue;
            }
            set
            {
                this.objValue = value;
            }
        }

        public string Description
        {
            get
            {
                return this.sDescription;
            }
        }

        public string Category
        {
            get
            {
                return this.sCategory;
            }
            set
            {
                this.sCategory = value;
            }
        }
        #endregion
    }

    /// <summary>
    /// PropertyDescriptor
    /// </summary>
    public class EntityPropertyDescriptor : PropertyDescriptor
    {
        #region Declarations
        EntityProperty m_Property;
        #endregion

        #region Constructors

        public EntityPropertyDescriptor(ref EntityProperty myProperty, Attribute[] attrs)
            : base(myProperty.Name, attrs)
        {
            m_Property = myProperty;
        }
        #endregion

        #region Public Properties

        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override Type ComponentType
        {
            get { return null; }
        }

        public override object GetValue(object component)
        {
            return m_Property.Value;
        }

        public override string Description
        {
            get { return m_Property.Description; }
        }

        public override string Category
        {
            get { return m_Property.Category; }
        }

        public override string DisplayName
        {
            get { return m_Property.Name; }
        }

        public override bool IsReadOnly
        {
            get { return m_Property.ReadOnly; }
        }

        public override void ResetValue(object component)
        {
            //Have to implement
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }

        public override void SetValue(object component, object value)
        {
            m_Property.Value = value;
        }

        public override Type PropertyType
        {
            get { return m_Property.Type; }
        }

        #endregion


    }

}
